package com.atguigu.stgy.model.result;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import lombok.Data;

@Data
public class R<T> {
    private Integer code;
    private String message;
    private T data;
    private Boolean ok;

    public static <T> R<T> build(Integer code, String message, T data, Boolean ok){
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        r.setOk(ok);
        return r;
    }
    public  static  <T> R<T> ok(){
        return build(200,"SUCCESS",null,true);
    }
    public  static  <T> R<T> ok(T data){
        return build(200,"SUCCESS",data,true);
    }
    public  static  <T> R<T> fail(){
        return build(201,"ERROR",null,false);
    }
    public  static  <T> R<T> fail(ResultCodeEnum codeEnum){
        return build(codeEnum.getCode(),codeEnum.getMessage(),null,false);
    }
    public  static  <T> R<T> fail(Integer code,String message){
        return build(code,message,null,false);
    }

}
